package com.alan.es.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;


/**
 * 商品实体类
 * 自定义mapping关系是通过实体类进行控制的
 * @Document 注解 org.springframework.data.elasticsearch.annotations
 * 定义类和索引的关系
 */
@Document(indexName = "index_item",shards = 1,replicas = 1)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Item {
    /**
     * 在SpringData ES中要求所有的属性都必须要有对应注解，否则自动映射
     */
    @Id
    //ID起名“id”和“_id” 都可以
    @Field(type = FieldType.Keyword)
    private String id;
    /*
    非主键都用Field注解
        如果希望Document和实体类中都叫做 title，那么 @Field(value = "")
        value不用填值，如果希望名字不一样，那就需要填值
     */
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String title;
    @Field(type = FieldType.Long)
    private Long price;
    @Field(type = FieldType.Text)
    private String catName;

    @Override
    public String toString() {
        return "Item{" +
                "id='" + id + '\'' +
                ", title='" + title + '\'' +
                ", price=" + price +
                ", catName='" + catName + '\'' +
                '}'+"\n";
    }
}
